#include <iostream>
#include <vector>

using namespace std;

class Solution {
    int mod = 10e9 + 7;
public:
    int kConcatenationMaxSum(vector<int>& arr, int k) {
        int n = arr.size();
        int pre = 0;
        int after = 0;
        long long sum = 0;
        for (int i = 0; i < k * n; i++){
            sum = (arr[i % n] + sum) % mod;
            pre = min(sum, pre * 1LL);
            after = max(sum, after * 1LL);
        }
        return after - sum;
    }
};